import Cookies from 'js-cookie';
import { ErrorBoundary } from 'react-error-boundary';

import type { IRouteComponentProps } from 'umi';

import PageErrorByBoundary from '@/components/Error/PageErrorByBoundary';

export default function BasicLayout({ children, location }: IRouteComponentProps) {
  const path = location.pathname.toLowerCase();

  console.log(path);

  if (path === '/login') {
    return <>{children}</>;
  }

  if (!Cookies.get('saas_token')) {
    // history.replace('/login');
  }

  const domChildren = (
    <ErrorBoundary
      FallbackComponent={PageErrorByBoundary}
      onReset={() => {
        // reset the state of your app so the error doesn't happen again
      }}
    >
      {children}
    </ErrorBoundary>
  );

  return <div style={{ width: '100%' }}>{domChildren}</div>;
}
